<?php

namespace app\openapi\validator;

use think\facade\Cache;
use think\Validate;

class GetPaymentValidator extends Validate
{
    protected $rule = [
        'order_num' => 'require|checkOrderNum'
    ];

    protected $message = [
        'order_num.require' => '订单号不能为空',
        'order_num.checkOrderNum' => '未知订单号',
    ];

    /**
     * 验证订单号
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool
     */
    protected function checkOrderNum($value, $rule, $data = [])
    {
        $redis = Cache::store('redis')->handler();
        $orderStateKey = implode(':', ['order_state', $value]);
        $exist = $redis->exists($orderStateKey);

        return $exist ? true : false;
    }
}